/**
 * Project  : Looker
 * Package  : net.freestu.looker.common
 * File     : Site.java
 * Author   : solosky < solosky772@qq.com >
 * Date     : Aug 21, 2009
 * Modified : Aug 21, 2009
 * License  : Apache License 2.0 
 */
package net.freestu.looker.common;


import java.util.ArrayList;

import net.freestu.looker.util.HashUtils;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 *  站点
 * @author  solosky
 * @version v1.0
 */
public class Site
{
	/**
	 * 站点编号
	 */
	private String hash;
	
	/**
	 * 站点标题
	 */
	private String title;
	
	/**
	 * 站点首页
	 */
	private String url;
	
	/**
	 * 栏目列表
	 */
	private ArrayList<Category> categoryList;
	
	/**
	 * 站点配置
	 */
	private Configuration config;
	
	/**
	 * 构造函数
	 */
	public Site(Configuration conf)
	{
		//加载站点配置
		config =  conf;
		title  = config.getString("site.title");
		url    = config.getString("site.url");
		hash   = HashUtils.shortHash(url);
		categoryList = new ArrayList<Category>();
		
		//加载站点栏目配置
		int cates = config.getList("categorys.category.title").size();
		XMLConfiguration xmlConfig = (XMLConfiguration) config;
		Category category = null;
		for(int i=0; i<cates; i++) {
			category = new Category(xmlConfig.configurationAt("categorys.category("+i+")"), this);
			categoryList.add(category);
		}
		
	}

	public String getHash()
    {
    	return hash;
    }

	public String getUrl()
	{
		return url;
	}
	
	public String getTitle()
    {
    	return title;
    }

	public ArrayList<Category> getCategoryList()
    {
    	return categoryList;
    }

	public Configuration getConfig()
    {
    	return config;
    }
	
	public String toString()
	{
		return new ToStringBuilder(this)
		.append("hash",hash)
		.append("title",title)
		.append("url",url)
		.toString();
	}
}
